﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Markup;
using System.Xml;
using UIT.Web.Controls.Template;

namespace UIT.Web.Renderers.Specials
{
	static class BindingRenderer
	{
		public static void Render(this Binding binding, XmlWriter writer)
		{
			if (binding != null)
			{
				StringBuilder sb = new StringBuilder();
				sb.Append(@"{""val"":""");
				sb.Append(binding.Path);
				sb.Append(@"""");
				if (!string.IsNullOrEmpty(binding.StringFormat))
				{
					sb.Append(@", ""format"":""");
					sb.Append(binding.StringFormat);
					sb.Append(@"""");
				}
				sb.Append("}");
				writer.WriteAttributeString("data-bind", sb.ToString());
			}
		}
	}
}